<?php
	class CommentControl extends Control{

		function commentshow(){
			$db=M('comment');
			// $total = $db->count();
			$sql="select count(*) from ".C('DB_PREFIX')."comment where over=1;";
			$num=M()->query($sql);
			$total = $num[0]['count(*)'];
			$page=new page($total);
			$result=$db->where(array('over'=>1))->findall($page->limit());

			$this->assign('result',$result);
			$this->display();
			echo $page->show();
		}

		function addcom(){
			$db=M('comment');
			// p($_POST);die;
			$_POST['addtime']=time();
			if ($db->add()) {
				$this->success('评论成功，正在审核请耐心等待');
			}
		}

		function commentdel(){
			$db=M('comment');
			$cmid=$_GET['cmid'];
			if ($db->where(array('cmid'=>$cmid))->del()) {
				$this->success('删除成功');
			}else{
				$this->error('删除失败，请重试');
			}
		}

		function commentpass(){
			$db=M('comment');
			$cmid = $_GET['cmid'];
			$sql="update ".C('DB_PREFIX')."comment set over=1 where cmid=$cmid";
			if ($db->exe($sql)>=0) {
				$this->success('评论已通过审核');
			}
		}

		function commentcheck(){
			$db=M('comment');
			// $cmid = $_GET['cmid'];
			$sql1="select count(*) from ".C('DB_PREFIX')."comment where over=0;";
			$num=M()->query($sql1);
			$total = $num[0]['count(*)'];
			$page=new page($total);
			$result=$db->where(array('over'=>0))->findall($page->limit());
			$this->assign('result',$result);
			$this->display();
			echo $page->show();
		}
	}

?>